﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace YXShop.Web.membercenter.circlereview
{
    public partial class shortmessage_feedback : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {  
                if (Session["MemberName"] == null)
                {
                    ChangeHope.WebPage.Script.AlertAndGoBack("温馨提示：请重新登录！");
                }
                if (ChangeHope.WebPage.PageRequest.GetFormString("Option") != string.Empty && ChangeHope.WebPage.PageRequest.GetFormString("id") != string.Empty)
                {
                    string types = Request.Form["Option"].Trim();
                    string StrID = ChangeHope.WebPage.PageRequest.GetFormString("id");
                    if (types == "del")
                    {
                        Del(StrID);
                    }
                    Response.End();
                    return;
                }
                this.lblList.Text = GetList();
            }
        }

        protected string GetList()
        {
            ChangeHope.WebPage.Table table = new ChangeHope.WebPage.Table();
            YXShop.BLL.Accessories.Leaveword bll = new YXShop.BLL.Accessories.Leaveword();
            ChangeHope.DataBase.DataByPage dataPage = bll.GetList(" 1=1 and username='" + Session["MemberName"].ToString() + "'");
            //第一步先添加表头
            table.AddHeadCol("", "<input type=\"checkbox\" id=\"chkAll\" onclick=\"CheckAll(this.form)\" alt=\"全选/取消\" />选择");
            table.AddHeadCol("", "留言时间");
            table.AddHeadCol("", "留言类别");
            table.AddHeadCol("", "留言内容");
            table.AddHeadCol("", "操作");
            table.AddRow();
            //添加表的内容
            if (dataPage.DataReader != null)
            {
                int curpage = ChangeHope.WebPage.PageRequest.GetInt("pageindex");
                if (curpage < 0)
                {
                    curpage = 1;
                }
                int count = 0;
                while (dataPage.DataReader.Read())
                {
                    count++;
                    string No = (15 * (curpage - 1) + count).ToString();
                    table.AddCol("<input ID=\"cBox\" type=\"checkbox\" value=\"" + dataPage.DataReader["id"].ToString() + "\" />");
                    string title = ChangeHope.Common.StringHelper.SubStringAndAppend(dataPage.DataReader["title"].ToString(), 30, "...");
                    string url = YXShop.TemplateAction.Common.UrlStr("leaveword_detail", "id=" + dataPage.DataReader["id"].ToString(), "membercenter/circlereview/");                
                    table.AddCol(dataPage.DataReader["adddate"].ToString());
                    table.AddCol(GetTypeName(dataPage.DataReader["type"].ToString()));
                    table.AddCol(string.Format("<a href=\'" + url + "\''>{0}</a>", title));              
                    table.AddCol(string.Format("<a href='javascript:void(0)' onclick='Del({0})'>删除</a>", dataPage.DataReader["id"].ToString()));
                    table.AddRow();
                }
            }
            string view = table.GetTable() + dataPage.PageToolBar;
            dataPage.Dispose();
            dataPage = null;
            return view;
        }

        protected string GetTypeName(string typeId)
        {
            string name = string.Empty;
            switch (typeId)
            {
                case "1":
                    name = "普通反馈";
                    break;
                case "2":
                    name = "购物投诉";
                    break;
                case "3":
                    name = "询问求购";
                    break;
                case "4":
                    name = "售后咨询";
                    break;
                case "5":
                    name = "加盟合作";
                    break;
            }
            return name;
        }

        private void Del(string id)
        {
            YXShop.BLL.Accessories.Leaveword bll = new YXShop.BLL.Accessories.Leaveword();
            bll.Delete(id);
            Response.Write("ok");
        }
    }
}
